/**
 * Created by zhang on 2014-11-29.
 */

//
function addLoadEvent(func){

    var oldonload = window.onload;
    if(typeof window.onload != 'function'){
        window.onload = func;
    }else{
        window.onload = function(){
            oldonload();
            func();
        }
    }
}

// 把现有元素后插入一个新元素
function insertAfter(newElement,targetElement){
    var parent = targetElement.parentNode;

    if(parent.lastChild == targetElement){
        parent.appendChild(newElement);
    }else{
        parent.insertBefore(newElement,targetElement.nextSibling);
    }
}

//检测XMLHTTPRequest；
function getHTTPObject(){
    if(typeof XMLHttpRequest == "undefined")
        XMLHttpRequest = function(){
            try{return new ActiveXObject("Msxml2.XMLHTTP.6.0");}
                catch(e){}
            try{return new ActiveXObject("Msxml2.XMLHTTP.3.0");}
                catch(e){}
            try{return new ActiveXObject("Msxml2.XMLHTTP");}
                catch(e){}
            return false;
        }
    return new XMLHttpRequest();
}
//
function getNewContent(){
    var request = getHTTPObject();
    if(request){
        request.open("GET","exam.txt",true);
        request.onreadystatechange = function () {
            if(request.readyState == 4){
                alert("Respond Recived");
                var para = document.createElement("p");
                var txt = document.createTextNode(request.responseText);
                para.appendChild(txt);
                document.getElementById("new").appendChild(para);
            }
        };
        request.send(null);
    }else{
        alert('Sorry,Your brower 不支持XMLHTTPRequest');
    }
    alert("Function Done");
}